#ifdef _FULLPROGRAM

#include "kstrpool.h"
#include <cstring>

void StringPool::Allocate(k_int poolSize)
{
	if (this->pool)
	{
		delete[] this->pool;
		this->ptr = 0;
		this->table.clear();
	}

	if (poolSize)
		this->pool = new char[poolSize];
}

void StringPool::AddString(const k_string &str)
{
	std::map<k_string, k_int>::iterator it = this->table.find(str);

	if (it == this->table.end())
	{
		int len = strlen(str.c_str()) + 1;
#ifdef _MSC_VER
		strcpy_s(this->pool + this->ptr, len, str.c_str());
#else
		strncpy(this->pool + this->ptr, str.c_str(), len);
#endif
		this->table[str] = this->ptr;
		this->ptr += len;
	}
}

k_int StringPool::GetStringAddress(const k_string &str)
{
	return this->table[str];
}

const char* StringPool::GetPool() const
{
	return this->pool;
}

void StringPool::CleanUp()
{
	delete[] this->pool;
	this->pool = 0;
	this->ptr = 0;
	this->table.clear();
}

#endif //_FULLPROGRAM
